package splash;

import android.graphics.Canvas;
import android.view.SurfaceHolder;

public class SplashThread extends Thread {
	private SurfaceHolder surfaceHolder;
	private SplashView splashView;
	private boolean finish = true;

	public SplashThread(SurfaceHolder surfaceHolder, SplashView splashView) {
		super();
		this.surfaceHolder = surfaceHolder;
		this.splashView = splashView;
	}

	public boolean isFinish() {
		return finish;
	}

	public void setFinish(boolean isStop) {
		this.finish = isStop;
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		Canvas canvas;
		while (!finish) {
			canvas = null;
			try {
				canvas = surfaceHolder.lockCanvas(null);
				synchronized (surfaceHolder) {
					splashView.onDraw(canvas);
				}
			} catch (Exception e) {
				// TODO: handle exception

			} finally {
				if (canvas != null)
					surfaceHolder.unlockCanvasAndPost(canvas);
				try {
					SplashThread.sleep(3000);

				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				splashView.surfaceDestroyed(surfaceHolder);
			}
		}
	}
}
